<?php

class Account extends AppModel {
    var $name = 'Account';
    // TODO# addd proper validation fields
    var $validate = array(
        'id' => array(
            'blankOnCreate' => array(
                'rule' => 'blank',
                'on' => 'create'
            )
        ),
        'email' => array(
            'between' => array(
                'rule' => array('between', 4, 100),
				// TODO# notice Shouldn't we make these messages i18n-able?
                'message' => 'Password must be between 4 and 100 characters long'
            ),
            'email' => array(
                'rule' => 'email',
                'message' => 'Please enter a valid email address'
            ),
            'unique' => array(
                'rule' => 'isUnique',
                'message' => 'That email address is already in use by another user'
            )
        ),
        'password' => array(
            'between' => array(
                'rule' => array('between', 4, 64),
                'message' => 'Password must be between 4 and 64 characters long'
            ),
        ),
        'confirm_password' => array(
            'emptyUpdate' => array(
                'rule' => 'emptyUpdate',
                'required' => true,
                'on' => 'update',
                'message' => 'Please confirm the password'
            ),
            'match' => array(
                'rule' => 'matchPasswords',
                'required' => true,
                'message' => 'The passwords you entered do not match'
            )
        )
    );
    var $hasMany = array(
            'Memo' => array(
                    'className' => 'Memo',
                    'foreignKey' => 'account_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            ),
            'MemoAsSender' => array(
                    'className' => 'Memo',
                    'foreignKey' => 'sender',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            )
    );

    function emptyUpdate() {
        return empty($this->data['Account']['password']) || !empty($this->data['Account']['confirm_password']);
    }

    function matchPasswords() {
        return $this->data['Account']['password'] == $this->data['Account']['confirm_password'];
    }
}
?>